<?php

namespace app\utils\script\ele\feedback;

use app\utils\script\JSScript;

/**
 * ElMessage信息
 */
class Message implements JSScript{
    private $txt = '';
    private $arg = '';

    /**
     * @param string $message 信息
     * @param string $type 提示类型 'success' | 'warning' | 'info' | 'error'
     * @param string $arg 整个JS作为函数体内的内容时传递此参数，作为代码片段则不要传递
     */
    public function __construct($message,$type='success',$arg='')
    {
        if($message instanceof JSScript){
            $message=$message->text();
        }else{
            $message='`'.$message.'`';
        }
        $this->arg= $arg;
        $this->txt= '
        ElementPlus.ElMessage({
            message:'.$message.',
            type:"'.$type.'"
        });
        ';
    }
    public function text(){
        return $this->txt;
    }
    public function argv(){
        return '('.$this->arg.')';
    }
}